<?php
	session_start();
	
$mysql_host = "mysql16.000webhost.com";
$mysql_database = "a1863493_venture";
$mysql_user = "a1863493_teamven";
$mysql_password = "teamventure1";

$link = mysql_connect($mysql_host, $mysql_user, $mysql_password); 

if (!$link) 
{
	die('Could not connect: ' . mysql_error());
} 
echo 'Connected successfully'; 
mysql_select_db($mysql_database, $link) or die ("Fail");

$companyName = $_POST['curName'];
echo $companyName;

	// connect the current user with the business
	$username = $_SESSION['username'];
	$bus_acct = null;
	$cust_acct = null;
	
	// Get customer and business IDs
	$query = sprintf("SELECT idcust_acct FROM cust_acct WHERE name = '$username'");
	$return = mysql_query($query);
	if (mysql_num_rows($return)){
		$cust_acct = mysql_result($return ,0 );
	}
	$query = sprintf("SELECT idbus_acct FROM bus_acct WHERE name = '$companyName'");
	$return = mysql_query($query);
	if (mysql_num_rows($return)){
		$bus_acct = mysql_result($return,0 );
	}
	// check that the subscription doesn't exist
	
	// if it doesn't exist, make the subscription
	$query = sprintf("INSERT INTO bus_cust( idcust_acct, idbus_acct) VALUES ('$cust_acct', '$bus_acct')");	
	$result = mysql_query($query);
	
	echo "subscribe";
	header("Location: ../userHomepage.html"); 
?>